cmake_minimum_required(VERSION 3.16)
project(DataProcessProApp)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

message(STATUS "Using compiler: ${CMAKE_CXX_COMPILER}")

# -------------------- include dirs --------------------
set(PRO_ROOT ${PROJECT_SOURCE_DIR}/..)
include_directories(
    ${PRO_ROOT}/include/curl
    ${PRO_ROOT}/include/csv
    ${PRO_ROOT}/library/csv/
    ${PRO_ROOT}/src/common/include
    ${PRO_ROOT}/thirdParty/spdlog-1.15.3/include
)

# -------------------- source files --------------------
file(GLOB SRC_FILES
    ${PROJECT_SOURCE_DIR}/*.cpp
    ${PRO_ROOT}/src/common/src/*.cpp
    ${PRO_ROOT}/library/csv/*.cpp
)

# -------------------- static libraries --------------------

if (MSVC)
    set(CURL_STATIC_LIB "${PRO_ROOT}/thirdParty/Lib/VS/win64/${CMAKE_BUILD_TYPE}/libcurl.lib")
    set(SPDLOG_STATIC_LIB "${PRO_ROOT}/thirdParty/Lib/VS/win64/${CMAKE_BUILD_TYPE}/libspdlogStatic.lib")
elseif (MINGW OR GCC)# MinGW 或其他 GCC 兼容编译器
    set(CURL_STATIC_LIB "${PRO_ROOT}/thirdParty/Lib/MinGW/win64/${CMAKE_BUILD_TYPE}/libcurl.a")
    set(SPDLOG_STATIC_LIB "${PRO_ROOT}/thirdParty/Lib/MinGW/win64/${CMAKE_BUILD_TYPE}/libspdlogStatic.a")
elseif (UNIX AND NOT APPLE)# Linux / macOS
    # 假设你的库放在 thirdParty/Lib/Linux/x86_64/release 目录下
    set(CURL_STATIC_LIB "${PRO_ROOT}/thirdParty/Lib/Linux/${CMAKE_BUILD_TYPE}/libcurl.a")
    set(SPDLOG_STATIC_LIB "${PRO_ROOT}/thirdParty/Lib/Linux/${CMAKE_BUILD_TYPE}/libspdlogStatic.a")
endif()


# -------------------- platform libraries --------------------
# --- 修改: Windows 系统库，直接写在 target_link_libraries 内 ---
set(WINDOWS_LIBS "")
if(MSVC OR MINGW)
    # set(WINDOWS_LIBS ws2_32)
    set(WINDOWS_LIBS ws2_32 crypt32 bcrypt)
endif()

# --- 修改: Linux 系统库，自动查找 ---
set(UNIX_LIBS_FOUND "")
if(UNIX AND NOT APPLE)
    set(UNIX_LIBS ssl crypto z pthread nghttp2 brotlidec brotlicommon)
    foreach(lib ${UNIX_LIBS})
        find_library(LIB_${lib}_PATH NAMES ${lib})
        if(LIB_${lib}_PATH)
            list(APPEND UNIX_LIBS_FOUND ${LIB_${lib}_PATH})
        else()
            message(FATAL_ERROR "Cannot find library: ${lib}")
        endif()
    endforeach()
endif()

# -------------------- executable --------------------
add_executable(DataProcessPro ${SRC_FILES})

# --- 修改: 定义宏 ---
target_compile_definitions(DataProcessPro PRIVATE
    CSVLIB_EXPORTS
    CURL_STATICLIB
)

# --- 修改: 链接库 ---
target_link_libraries(DataProcessPro PRIVATE
    ${CURL_STATIC_LIB}
    ${SPDLOG_STATIC_LIB}
    ${CSV_LIBRARY}
    ${WINDOWS_LIBS}       # Windows 下系统库
    ${UNIX_LIBS_FOUND}    # Linux 下系统库
)

# -------------------- output dir --------------------
set_target_properties(DataProcessPro PROPERTIES
    RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Bin
)
